﻿using NicoView.Model.Platform.MediaEncoders;
using NicoView.Model.Service;
using NicoView.Model.Share.MediaEncoders;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NicoView.Model.MediaEncoder
{
    public class MediaEncoders : NicoViewObservableObject
    {

        public MediaEncoders()
        {
            providers = new ObservableCollection<IBroadcastMediaEncoderProvider>();
            this.setProviders(NicoViewBrodcastEncodersFactory.Current.CreateEncoders());
        }


        private IBroadcastMediaEncoderProvider currentProvider;

        public IBroadcastMediaEncoderProvider CurrentProvider
        {
            get
            {
                return this.currentProvider;
            }

            set
            {
                this.Set(() => this.CurrentProvider, ref this.currentProvider, value);
            }
        }

        private ICollection<IBroadcastMediaEncoderProvider> providers;

        public IBroadcastMediaEncoder Create()
        {
            if (this.CurrentProvider != null)
            {
                return this.CurrentProvider.Create();
            }

            return null;
        }

        private void setProviders(IEnumerable<IBroadcastMediaEncoderProvider> providers)
        {

            foreach (var provider in providers)
            {
                this.providers.Add(provider);
            }

            if (this.providers.Any())
            {
                this.CurrentProvider = this.providers.First();
            }
        }

        /// <summary>
        /// 割り当てられたインスタンス
        /// </summary>
        public static MediaEncoders Current = new MediaEncoders();
        
    }
}
